package com.easyctba.core.controller;

import java.util.List;

import com.easyctba.core.domain.CtbaFiasPolyline;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.easyctba.common.idempotent.annotation.RepeatSubmit;
import com.easyctba.common.log.annotation.Log;
import com.easyctba.common.web.core.BaseController;
import com.easyctba.common.mybatis.core.page.PageQuery;
import com.easyctba.common.core.domain.R;
import com.easyctba.common.core.validate.AddGroup;
import com.easyctba.common.core.validate.EditGroup;
import com.easyctba.common.log.enums.BusinessType;
import com.easyctba.common.excel.utils.ExcelUtil;
import com.easyctba.core.domain.vo.CtbaFiasPolylineVo;
import com.easyctba.core.domain.bo.CtbaFiasPolylineBo;
import com.easyctba.core.service.ICtbaFiasPolylineService;
import com.easyctba.common.mybatis.core.page.TableDataInfo;

/**
 * FIAS的折线图分析
 * 前端访问路由地址为:/core/fiasPolyline
 *
 * @author Huang
 * @date 2024-04-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fiasPolyline")
public class CtbaFiasPolylineController extends BaseController {

    private final ICtbaFiasPolylineService ctbaFiasPolylineService;

    /**
     * 查询FIAS的折线图分析列表
     */
    @SaCheckPermission("core:fiasPolyline:list")
    @GetMapping("/list")
    public TableDataInfo<CtbaFiasPolylineVo> list(CtbaFiasPolylineBo bo, PageQuery pageQuery) {
        return ctbaFiasPolylineService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出FIAS的折线图分析列表
     */
    @SaCheckPermission("core:fiasPolyline:export")
    @Log(title = "FIAS的折线图分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CtbaFiasPolylineBo bo, HttpServletResponse response) {
        List<CtbaFiasPolylineVo> list = ctbaFiasPolylineService.queryList(bo);
        ExcelUtil.exportExcel(list, "FIAS的折线图分析", CtbaFiasPolylineVo.class, response);
    }

    /**
     * 获取FIAS的折线图分析详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("core:fiasPolyline:query")
    @GetMapping("/{id}")
    public R<CtbaFiasPolylineVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(ctbaFiasPolylineService.queryById(id));
    }

    /**
     * 新增FIAS的折线图分析
     */
    @SaCheckPermission("core:fiasPolyline:add")
    @Log(title = "FIAS的折线图分析", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CtbaFiasPolylineBo bo) {
        return toAjax(ctbaFiasPolylineService.insertByBo(bo));
    }

    /**
     * 修改FIAS的折线图分析
     */
    @SaCheckPermission("core:fiasPolyline:edit")
    @Log(title = "FIAS的折线图分析", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CtbaFiasPolylineBo bo) {
        return toAjax(ctbaFiasPolylineService.updateByBo(bo));
    }

    /**
     * 删除FIAS的折线图分析
     *
     * @param ids 主键串
     */
    @SaCheckPermission("core:fiasPolyline:remove")
    @Log(title = "FIAS的折线图分析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(ctbaFiasPolylineService.deleteWithValidByIds(List.of(ids), true));
    }


    /**
     * 获取曲线名
     * @param id FIAS id
     * @return 折线LIST
     */
    @GetMapping("/front/polylineInfo/{id}")
    public R<List<CtbaFiasPolyline>> info(@NotNull(message = "FIAS ID不能为空") @PathVariable Long id){
        return ctbaFiasPolylineService.getInfo(id);
    }

    /**
     * 删除折线分析
     * @param id 折线 id
     */
    @DeleteMapping("/front/{id}")
    public R<Void> delete(@NotNull(message = "折线ID不能为空") @PathVariable Long id){
        return ctbaFiasPolylineService.delete(id);
    }
}
